package com.ssy.lingxi.member.merchant.entity;

import com.fasterxml.jackson.annotation.JsonManagedReference;
import com.ssy.lingxi.member.merchant.handler.converter.JpaJsonToFileListConverter;
import com.ssy.lingxi.member.merchant.model.bo.FileBO;

import javax.persistence.*;
import java.io.Serializable;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.util.List;

/**
 * 会员考评
 * @author yzc
 * @version 2.0.0
 * @date 2021/5/17
 */
@Entity
@Table(schema = "public", name = "ms_mc_member_appraisal")
public class MemberAppraisalDO implements Serializable {
    private static final long serialVersionUID = -8829661512042816007L;

    /**
     * 主键id
     */
    @Id
    @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "member_appraisal_seq")
    @SequenceGenerator(sequenceName = "ms_mc_member_appraisal_seq", name = "member_appraisal_seq", allocationSize = 1)
    private Long id;

    /**
     * 考评单号
     */
    @Column(columnDefinition = "varchar(20)")
    private String appraisalNo;

    /**
     * 内部状态 1-待发布考评表 2-待考评打分 3-待提交汇总考评结果 4-待审核考评结果(一级) 5-考评结果审核不通过(一级)
     * 6-待审核考评结果(二级) 7-考评结果审核不通过(二级) 8-待通报考评结果 9-已通报考评结果
     */
    @Column
    private Integer status;

    /**
     * 工作流任务Id
     */
    @Column
    private String taskId;

    /**
     * 考评主题
     */
    @Column(columnDefinition = "varchar(50)")
    private String subject;

    /**
     * 多对一单向关联上级会员
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "member_id", referencedColumnName = "id")
    private MemberDO member;

    /**
     * 上级角色
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "role_id", referencedColumnName = "id")
    private RoleDO role;

    /**
     * 多对一单向关联下级会员
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "sub_member_id", referencedColumnName = "id")
    private MemberDO subMember;

    /**
     * 下级会员角色
     */
    @ManyToOne(cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    @JoinColumn(name = "sub_role_id", referencedColumnName = "id")
    private RoleDO subRole;

    /**
     * 考评时间开始
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime appraisalTimeStart;

    /**
     * 考评时间结束
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime appraisalTimeEnd;

    /**
     * 考评完成时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime completeTime;

    /**
     * 总得分
     */
    @Column(columnDefinition = "numeric")
    private BigDecimal totalScore;

    /**
     * 考评结果
     */
    @Column(columnDefinition = "varchar(100)")
    private String result;

    /**
     * 通知会员考评结果 0-否 1-是
     */
    @Column
    private Integer notifyMember;

    /**
     * 考评附件
     */
    @Convert(converter = JpaJsonToFileListConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<FileBO> attachments;

    /**
     * 考评结果附件
     */
    @Convert(converter = JpaJsonToFileListConverter.class)
    @Column(columnDefinition = "jsonb")
    private List<FileBO> resultAttachments;

    /**
     * 会员考评项目
     */
    @JsonManagedReference
    @OneToMany(mappedBy = "appraisal", cascade = CascadeType.DETACH, fetch = FetchType.LAZY)
    private List<MemberAppraisalItemDO> items;

    /**
     * 创建时间
     */
    @Column(columnDefinition = "timestamp")
    private LocalDateTime createTime;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAppraisalNo() {
        return appraisalNo;
    }

    public void setAppraisalNo(String appraisalNo) {
        this.appraisalNo = appraisalNo;
    }

    public Integer getStatus() {
        return status;
    }

    public void setStatus(Integer status) {
        this.status = status;
    }

    public String getTaskId() {
        return taskId;
    }

    public void setTaskId(String taskId) {
        this.taskId = taskId;
    }

    public String getSubject() {
        return subject;
    }

    public void setSubject(String subject) {
        this.subject = subject;
    }

    public MemberDO getMember() {
        return member;
    }

    public void setMember(MemberDO member) {
        this.member = member;
    }

    public RoleDO getRole() {
        return role;
    }

    public void setRole(RoleDO role) {
        this.role = role;
    }

    public MemberDO getSubMember() {
        return subMember;
    }

    public void setSubMember(MemberDO subMember) {
        this.subMember = subMember;
    }

    public RoleDO getSubRole() {
        return subRole;
    }

    public void setSubRole(RoleDO subRole) {
        this.subRole = subRole;
    }

    public LocalDateTime getAppraisalTimeStart() {
        return appraisalTimeStart;
    }

    public void setAppraisalTimeStart(LocalDateTime appraisalTimeStart) {
        this.appraisalTimeStart = appraisalTimeStart;
    }

    public LocalDateTime getAppraisalTimeEnd() {
        return appraisalTimeEnd;
    }

    public void setAppraisalTimeEnd(LocalDateTime appraisalTimeEnd) {
        this.appraisalTimeEnd = appraisalTimeEnd;
    }

    public LocalDateTime getCompleteTime() {
        return completeTime;
    }

    public void setCompleteTime(LocalDateTime completeTime) {
        this.completeTime = completeTime;
    }

    public BigDecimal getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(BigDecimal totalScore) {
        this.totalScore = totalScore;
    }

    public String getResult() {
        return result;
    }

    public void setResult(String result) {
        this.result = result;
    }

    public Integer getNotifyMember() {
        return notifyMember;
    }

    public void setNotifyMember(Integer notifyMember) {
        this.notifyMember = notifyMember;
    }

    public List<FileBO> getAttachments() {
        return attachments;
    }

    public void setAttachments(List<FileBO> attachments) {
        this.attachments = attachments;
    }

    public List<FileBO> getResultAttachments() {
        return resultAttachments;
    }

    public void setResultAttachments(List<FileBO> resultAttachments) {
        this.resultAttachments = resultAttachments;
    }

    public List<MemberAppraisalItemDO> getItems() {
        return items;
    }

    public void setItems(List<MemberAppraisalItemDO> items) {
        this.items = items;
    }

    public LocalDateTime getCreateTime() {
        return createTime;
    }

    public void setCreateTime(LocalDateTime createTime) {
        this.createTime = createTime;
    }
}
